package com.java.yz.day15;

public class ConsumerDemo1 extends Thread{
    private Student s1;

    public ConsumerDemo1() {
    }

    public ConsumerDemo1(Student s1) {
        this.s1 = s1;
    }

    @Override
    public void run() {
        //Student s1 = new Student();
        while (true) {
            synchronized (s1){
                //如果没有就进去等待状态
                if (!s1.flag){
                    try {
                        s1.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }

                //如果有就进行打印
                System.out.println(s1.name + "--" + s1.age);
                s1.flag=false;
                //还要通知生产者生产
                s1.notify();


            }
        }
    }
}
